package myCine.global.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;

import myCine.alloCine.model.exchange.search.subClass.Movie;
import utils.FileUtils;
import utils.StringUtils;

public abstract class GlobalSearchManager {
	
	/*=========================
	 * PREPARE REQUEST/RESULT
	 *=========================*/

	protected static List<String> readAndSplit(final String path, final String spliter) throws UnsupportedEncodingException{
		String moviesTitles = FileUtils.readFile(path);
		return StringUtils.split(moviesTitles, spliter);
	}
	
	/**
	 * Prepare the name of the film
	 */
	protected static String getPreparedNameForSearch(final String title) throws UnsupportedEncodingException{
		return StringUtils.encode(title.trim().replaceAll("\\p{Zs}", " "));
	}
	
	/**
	 * Decode by default in UTF-8 :
	 * - original title
	 */
	protected static void decodeMovieString(final Movie movie) throws UnsupportedEncodingException{
		if(movie.getOriginalTitle() != null){
			movie.setOriginalTitle(StringUtils.decode(movie.getOriginalTitle()));
		}
		
		if(movie.getSynopsis() != null){
			movie.setSynopsis(StringUtils.decode(movie.getSynopsis()));
		}
	}
	
}
